﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using System.Text.RegularExpressions;

public partial class Teacher_ManageExhibitionDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Teacher"] == null)
        {
            Response.Redirect("~/Default.aspx");
        }
        else
        {
            //Neu Staff hoac Manager da login
            string user = Session["Teacher"].ToString();
            if (user[0] == 'T' || user[0] == 't' || user == "Manager" || user == "manager")
            {

            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }

    void AddError(Dictionary<GridViewColumn, string> errors, GridViewColumn column, string errorText)
    {
        if (errors.ContainsKey(column)) return;
        errors[column] = errorText;
    }


    protected void gvwExhibition_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
    {
        //Kiem tra  ko dc rong
        if (e.NewValues["PostingID"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["PostingID"], "PostingID can't be null.");
        }else if (e.NewValues["ExhibitionID"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["ExhibitionID"], "ExhibitionID can't be null.");
        }
        else if (e.NewValues["Money_Paid"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["Money_Paid"], "Money Paid can't be null.");
        }
        else if (e.NewValues["Firtname_Customer"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["Firtname_Customer"], "Firtname_Customer can't be null.");
        }
        else if (e.NewValues["Lastname_Customer"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["Lastname_Customer"], "Lastname_Customer can't be null.");
        }
        else if (e.NewValues["Address_Customer"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["Address_Customer"], "Address_Customer can't be null.");
        }
        else if (e.NewValues["Phone_Customer"] == null)
        {
            AddError(e.Errors, gvwExhibition.Columns["Phone_Customer"], "Phone_Customer can't be null.");
        }
        else
        {
            string phone = "^[0-9]{6,12}$";
            Regex rx = new Regex(phone, RegexOptions.IgnoreCase);
            if (e.NewValues["Phone"] != null && !rx.IsMatch(e.NewValues["Phone"].ToString()))
            {
                AddError(e.Errors, gvwExhibition.Columns["Phone_Customer"], "Phone number invalid. (Ex: 0942076550)");
            }
        }
    }
}